<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function setting($key) {
	$_CI = &get_instance();
	return $ci->setting->item($key);
}

function content_summary($str, $len = 120) {
	$str = strip_tags($str);

	return mb_substr($str, 0, $len, 'UTF-8');
} 

function data2tree($data, $root = 0, $cid = 'id', $pid = 'pid', $child = '_child') {
	$tree = array();
	$_temp = array();
	foreach ( $data as $key => $val ) {
		$_temp[$val[$cid]] = &$data[$key];
	}

	foreach ( $data as $key => $val ){
		$parentId = $val[$pid];

		if ($root == $parentId) {
			$tree[] = &$data[$key];
		} else {
			if (isset($_temp[$parentId])) {
				$parent = &$_temp[$parentId];
				$parent[$child][] = &$data[$key];
			}
		}
	}

	return $tree;
}

function get_ext($file) {
	$arr = explode('.', $file);
	$ext = array_pop($arr);

	return $ext;
}

function is_windows() {
	return (strpos(strtoupper(PHP_OS), 'WIN') !== FALSE) ? TRUE : FALSE;
}

// 获取服务器本地文件的文件名（防止windows和linux的中文名乱码）
function get_file_name($file_name) {
	
	if (is_windows()) {
		return iconv('GBK', 'UTF-8', $file_name);
	} else {
		return $file_name;
	}

}
// 创建文件时的文件名（防止windows和linux的中文名乱码）
function create_file_name($file_name) {
	
	if (is_windows()) {
		return iconv('UTF-8', 'GBK', $file_name);
	} else {
		return $file_name;
	}

}